import React, { Component } from 'react'
import ReactTimeout from 'react-timeout'
import { FormattedMessage, FormattedNumber } from 'react-intl'
import { myFetch, config, helper } from '../utils'
class TopAccount extends Component {
  state = {
    accountData: []
  }
  onAccountData = () => {
      const options = {
      method: 'POST'
    }
    myFetch(`${config.rootApi}/mAccount`, options, true)
      .then((rs) => {
        if (rs) {
          this.setState({
            accountData: rs
          })
        }
       // console.log(this.state.accountData)
         this.props.setTimeout(this.onAccountData, 5000)
      })
  }
  componentDidMount() {
    this.onAccountData()
  }
  render() {
    const data = this.state.accountData
    return (
      <div className="top-account">
        <span>
          <span>
            <FormattedMessage
              id="totalAssets"
            />
            <span className="rt-mo">
              <FormattedMessage
                id="simulation"
              />
            </span>
          </span>
          <span>
            <FormattedNumber
              value={data.netEquity || 0}
            />
          </span>
        </span>
        <span>
          <span>
            <FormattedMessage
                 id="availableFunds"
              />
          </span>
          <span>
            <FormattedNumber
              value={data.marginAvailable || 0}
            />
          </span>
        </span>
        <span>
          <span>
            <FormattedMessage
                 id="bond"
              />
          </span>
          <span>
            <FormattedNumber
              value={data.maintenanceMargin || 0}
            />
          </span>
        </span>
        <span>
          <span>
            <FormattedMessage
                 id="floating"
              />
          </span>
          <span>
            <FormattedNumber
              value={data.floatingPl || 0}
            />
          </span>
        </span>
      </div>
    )
  }
}
export default ReactTimeout(TopAccount)